package com.mengye.model;

import java.util.List;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.mengye.bean.TeacherInfoBean;
import com.mengye.bean.UserInfoBean;
import com.mengye.db.DBProvider;
import com.mengye.utils.EasyFactory;

public class UserInfoModel {
	
	/**	登录信息查询
	 * @param userInfoB
	 * @return
	 */
	public List<UserInfoBean> queryLoginInfo(UserInfoBean userInfoB){
		//声明查询语句，未确定项用？通配符
		String sql = "select * from userinfo where user_name = ? and user_psw =?";
		//进行查询
		List<UserInfoBean> lst = EasyFactory.getNewInstance(DBProvider.class).query(sql, 
				new BeanListHandler<UserInfoBean>(UserInfoBean.class),userInfoB.getUser_Name(),userInfoB.getUser_Psw());
		//返回结果集
		System.out.println(lst.size());
		return lst;
	}
	
	public int updateInfo(UserInfoBean userInfoB){
		int i = 0;
		String sql = "update userinfo set user_psw = ? where user_name = ? ";
		i=EasyFactory.getNewInstance(DBProvider.class).update(sql, userInfoB.getUser_Psw(),userInfoB.getUser_Name());
		return i;
	}
	
	public int updateInfo(TeacherInfoBean teacherInfoB){
		System.out.println(teacherInfoB.toString());
		int i = 0;
		String sql = "update teacher set t_email = ?,t_excel=? where t_id = ? ";
		i=EasyFactory.getNewInstance(DBProvider.class).update(sql, teacherInfoB.getT_Email(),teacherInfoB.getT_excel(),teacherInfoB.getT_id());
		return i;
	}
	
	/**	登录信息查询
	 * @param userInfoB
	 * @return
	 */
	public List<UserInfoBean> queryPsw(UserInfoBean userInfoB){
		//声明查询语句，未确定项用？通配符
		String sql = "select user_psw from userinfo where user_name = ? ";
		//进行查询
		List<UserInfoBean> lst = EasyFactory.getNewInstance(DBProvider.class).query(sql, 
				new BeanListHandler<UserInfoBean>(UserInfoBean.class),userInfoB.getUser_Name());
		//返回结果集
		System.out.println(lst.size());
		return lst;
	}
	
	/**	教师所有信息查询
	 * @return
	 */
	public List<UserInfoBean> queryAllTeaInfo(){
		//声明查询语句，未确定项用？通配符
		String sql = "select * from teacher ";
		//进行查询
		List<UserInfoBean> lst = EasyFactory.getNewInstance(DBProvider.class).query(sql, 
				new BeanListHandler<UserInfoBean>(UserInfoBean.class));
		//返回结果集
		System.out.println(lst.size());
		return lst;
	}
}
